<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/7/31 0031
 * Time: 下午 2:25
 */
namespace app\model;
class School extends \think\Model{
    public $table="school";

    function get_school_by_params($params=[]){
        if($params['p_id']!=false){
            $o=$this->where(['p_id'=>$params['id']]);
        }else{
            $o=$this;
        }
        if($params['edu_type']!=false){
            $o=$this->where(['edu_type'=>$params['edu_type']]);
        }else{
            $o=$this;
        }
        if($params['k']!=false){
            $o=$this->where('school_name','like',"%{$params[k]}%");
        }else{
            $o=$this;
        }
        $o=$this->select();
        $arrs=object2array($o);
        foreach ($arrs as $k=>$v) {
            $arrs[$k]['pic']=pic_host($v['pic']);
        }
        return $arrs;
    }

    /**
     * 根据学校ID,返回他的学校名字
     * @param $id
     * @return string
     */
    function get_school_name_by_id($id){
        $o=$this->where(['id'=>$id])->column("school_name");
        if($o[0]){
            return $o[0];
        }else{
            return '';
        }
    }

    function get_all_school(){
        $o=$this->field("id,school_name")->select();
        $arrs=object2array($o);
        return $arrs;

    }

    function get_school_info_by_id($id){
        $o=$this->where(['id'=>$id])->find();
        $arr=object2array($o);
        if($arr){
            $arr['pic']=pic_host($arr['pic']);
        }
        return $arr;
    }
}